home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 2003 September / PC Answers September 2003.iso / Software / trial / MonitorIT 5.2.06 / monitorit_fullsetup.exe / data1.cab / Js / IntroGraph.js < prev    next >
Encoding:
JavaScript  |  2003-06-24  |  8.6 KB  |  243 lines

  1. /* ======================================================================
  2. DESC: Intro Graph Feature Called from RpmIntro.asp
  3.  
  4. PLATFORMS: >= MS IE 4.0
  5. USAGE NOTES: 
  6. ====================================================================== */
  7.  
  8.  
  9. // Process Request from Intro Page to Show Graph of Local PC
  10. var IgItem = null; // Group Handle
  11. var Ic = null; // Computer name
  12. var IcItem = null; // Computer Handle
  13. var Io = null; // Object Name
  14. var IoItem = null; // Object Handle
  15. var Icnt = null; // Counter Name
  16. var IcntItem = null; // Counter Handle
  17. var CMo = null; // Computer Serach Type
  18. var CItem = null; // Item Handle
  19. var IntroGraphO = null; // Intro Graph Object
  20. var IntroGraphStateF = 0; // Intro Graph State flag
  21. var ProcPerfChecked = false; // processor performance Monitoring should be reset
  22. var InvEventExpected = null;
  23.  
  24. var NTProcObject = "Processor   0";
  25. var NTProcCntrName = "% Processor Time";
  26. var ProcObject98 = "Kernel";
  27. var ProcCntrName98 = "Processor Usage (%)";
  28. var ProcCntrName = null;
  29. var SB_RIGHT = 7; // Scroll Bar set for chart
  30. var State6Retry = 0;
  31.  
  32. // Tree Serach definitions
  33. var Expand = 2;
  34. var Collapse = 1;
  35. var Root = 0;
  36. var FirstVisible = 5;
  37. var Next = 1;
  38. var Child = 4;
  39. var Caret = 9;
  40. var Tree = null;
  41.  
  42. function processIntroGraphMode() {    
  43.     Tid = null; // reset
  44.     // Process based on State flag
  45.     switch ( IntroGraphStateF ) {
  46.     
  47.    case 0 : // Initial Entry
  48.         if ( top.banner.IntroGraphMode == false )     
  49.             return;
  50.         top.banner.IntroGraphMode = false; // reset
  51.         top.main.restoreReduced(); // insure Tree pane is reduced in size
  52.         top.main.TreePane.InventoryEventHandling = true; // Enable Tree Inventory Event handler
  53.         Tree = top.main.TreePane.document.all.RPMTree; // Tree object
  54.         top.Rstatus.Pstat("Searching for Local Computer '"+top.banner.IntroGraphAgentName+"' in Network Tree");
  55.     case 1 :
  56.         if ( IntroGraphStateF == 0 ) {
  57.             stat = Tree.GetNextItem(1,0,Root); // Get First Group
  58.             top.Rstatus.Pstat("Group: "+stat);
  59.             if ( stat == "Disconnected" || stat == "No Groups" ) {
  60.                 break;
  61.             }
  62.         }
  63.         else {
  64.             Tree.GetNextItem(1,IgItem,Next); // Get Next Group
  65.         }    
  66.         if ( (IgItem = Tree.CurItem) == 0 ) { // Handle to Group; if not found, tell user
  67.             alert("Cannot find Local Computer '"+top.banner.IntroGraphAgentName+"' in Network Tree");
  68.             IntroGraphStateF = 0;
  69.         }
  70.         else {
  71.             InvEventExpected = IntroGraphStateF = 90; // Set State flag; wait for Event
  72.             Tree.ExpandItem(1,IgItem,Expand); // Expand Group to Computers
  73.             CMo = Child; CItem = IgItem; // Set to get first computer in Group
  74.         }
  75.         break;
  76.         
  77.    case 90 : // Group Expanded Event
  78.         IntroGraphStateF = 2; // Delay before processing Computers
  79.         break;
  80.  
  81.    case 2: // Group Expnaded, Look at each Computer in Group for Match
  82.         for ( ; CItem != 0;  ) { // Look at Computers in the Group
  83.             Ic = Tree.GetNextItem(1,CItem,CMo); // Next Computer in Group
  84.             CItem = IcItem = Tree.CurItem; // Handle to Local Computer
  85.             CMo = Next; // Get Next
  86.             if ( Ic == top.banner.IntroGraphAgentName ) { // if found
  87.                break;
  88.             }
  89.         }
  90.         if (IcItem == 0 ) { // if Computer not found
  91.             Tree.ExpandItem(1,IgItem,Collapse); // Collapse this Group, get Next Group
  92.             IntroGraphStateF = 1; // Set State flag
  93.         }
  94.         else  {
  95.             Tree.Selectitem(1,IcItem,Caret); // Highlight Computer
  96.             if ( !Tree.CurConnected ) { // if not connected
  97.                 Tree.SetConnected(1,IcItem,true); // tell it to connect
  98.             }
  99.             top.Rstatus.Pstat("Found Local Computer: '"+top.banner.IntroGraphAgentName+"'");
  100.             InvEventExpected = IntroGraphStateF = 91; // Set State flag; wait for Event
  101.             Tree.ExpandItem(1,IcItem,Expand); // Expand Computer to Objects
  102.             CMo = Child; CItem = IcItem; // Set to get first Object in Computer
  103.         }
  104.       break;
  105.  
  106.     case 91 : // Find Processor Object to Monitor
  107.         for ( ; CItem != 0;  ) { // Look at Objects in the Computer
  108.             getNextObject(); // get next Object
  109.             if ( Io == ProcObject98 ) {
  110.                 ProcCntrName = ProcCntrName98;
  111.                break;
  112.             }
  113.             else if ( Io == NTProcObject ) {
  114.                 ProcCntrName = NTProcCntrName;
  115.                break;
  116.             }
  117.         }
  118.         if ( IoItem == 0 ) { // if Object not found
  119.             IntroGraphStateF = 0; // ReSet State flag
  120.             alert("Cannot find Object to Graph");
  121.         }
  122.         else  {
  123.             Tree.Selectitem(1,IoItem,Caret); // Highlight Object
  124.             top.Rstatus.Pstat("Found Processor Object");
  125.             InvEventExpected = IntroGraphStateF = 92; // Set State flag; wait for Event
  126.             ExpandObject(); // Expand Object to Counters
  127.         }
  128.       break;
  129.  
  130.     case 92 : // Find Processor Counters to Monitor
  131.         for ( ; CItem != 0;  ) { // Look at Counters in the Objects
  132.             getNextCounter(); // get next Counter
  133.             if ( Icnt == ProcCntrName ) { // if found
  134.                 Tree.Selectitem(1,IcntItem,Caret); // Select it for add to the Chart
  135.                 Tree.SetChecked(1,IcntItem,true); // check it for monitoring
  136.                 ProcPerfChecked = true;  // flag to reset on exit from View Charts
  137.                break;
  138.             }
  139.         }
  140.         if (IcntItem == 0 ) { // if Counter not found
  141.             IntroGraphStateF = 0; // ReSet State flag
  142.             alert("Cannot find Counter to Graph");
  143.         }
  144.         else  {
  145.             top.Rstatus.Pstat("Found Processor Performance Counter");
  146.             IntroGraphStateF = 5; // Set State flag
  147.         }
  148.        break;
  149.        
  150.     case 5 : // See If Graph Already Exists and if so Open it
  151.         top.Rstatus.Pstat("Searching for Existing Local Computer Chart");
  152.         top.banner.DemoMode = true; // indicate in Demo mode
  153.         ChartOpenName = top.banner.IntroGraphAgentName+" Processor Performance";
  154.         OpenBkMrk = 9998; // Return here via "processViewChartsBookmarks()" if Open succeeds
  155.         ChartNotFoundBid = 9999; // Return here via "processViewChartsBookmarks()" if Open fails
  156.         IntroGraphStateF = 0; // ReSet State flag
  157.         doButtonProcessing("Open");
  158.         break;
  159.         
  160.     case 9998 : // Graph for Local Agent Already Exists and is now Open
  161.         State6Retry = 0; // reset retry count
  162.     case 6 :
  163.         if ( FullViewChartName == null ) {
  164.             IntroGraphStateF = 0; // reset IntroGraph Mode if active
  165.             top.banner.IntroGraphMode = false;
  166.             return;
  167.         }
  168.          IntroGraphO = document.all["RpmGrph"+FullViewChartName]; // Selected Graph Object
  169.          // Wait until Chart has been loaded before moving on
  170.          ++State6Retry; // bump retry counter
  171.        if ( document.all[FullViewChartName].HData == true ) { //|| State6Retry > 20) {
  172.              IntroGraphStateF = 10; // Set State flag
  173.               doButtonProcessing("Add"); // insure Performance counter is on the Chart
  174.         }
  175.         else {
  176.              IntroGraphStateF = 6; // Set State flag
  177.         }
  178.         break;    
  179.  
  180.     case 9999 : // Existing Graph for Local Agent not Found
  181.         top.Rstatus.Pstat("Creating New Chart for Local Computer");
  182.         IntroGraphStateF = 7; // Delay before Creating New Graph
  183.         break;
  184.  
  185.     case 7 : // Create New Graph 
  186.         IntroGraphStateF = 8; // Set State flag
  187.        doButtonProcessing("New");
  188.         break;    
  189.  
  190.     case 8 : // Add Counters and Set Name
  191.         IntroGraphO = document.all["RpmGrph"+FullViewChartName]; // Selected Graph Object
  192.         IntroGraphO.SetGraphName(top.banner.IntroGraphAgentName+" Processor Performance");
  193.         IntroGraphStateF = 6; // Set State flag
  194.           doButtonProcessing("Add");
  195.         break;    
  196.  
  197.     case 10 : // Set Slider on Chart to Right for Current Time
  198.         top.Rstatus.Pstat("Local Performance Chart Named: '"+top.banner.IntroGraphAgentName+" Processor Performance'");
  199.         IntroGraphStateF = 11; // Set State flag
  200.         IntroGraphO.SetHScrollPos(SB_RIGHT); // set slider tab
  201.         break;    
  202.  
  203.     case 11 : // Start Play
  204.         doButtonProcessing("Play");
  205.         IntroGraphStateF = 0; // ReSet State flag
  206.         top.main.TreePane.InventoryEventHandling = false; // Disable Tree Inventory Event handler
  207.         break;    
  208.     }
  209.     if ( IntroGraphStateF != 0 && IntroGraphStateF < 90) { // Set T/O for Reentry
  210.         Tid = setTimeout("processIntroGraphMode()",3000); // Delay 3 secs
  211.     }
  212. }
  213.  
  214. // Get Next Object for Computer
  215. function getNextObject() {
  216.     Io = Tree.GetNextItem(1,CItem,CMo); // Next Object in Computer
  217.     CItem = IoItem = Tree.CurItem; // Handle to Object
  218.     CMo = Next; // Get Next
  219. }
  220.  
  221. // Expand Object to Show Counters
  222. function ExpandObject() {
  223.     Tree.ExpandItem(1,IoItem,Expand); // Expand Object to Counter
  224.     CMo = Child; CItem = IoItem; // Set to get first Counter in Object
  225. }
  226.  
  227. // Get Next Counter for Object
  228. function getNextCounter() {
  229.     Icnt = Tree.GetNextItem(1,CItem,CMo); // Next Counter in Object
  230.     CItem = IcntItem = Tree.CurItem; // Handle to Counter
  231.     CMo = Next; // Get Next
  232. }
  233.  
  234. // Process the Tree Inventory Event as a Result of Expand() on a Group, Computer or Object
  235. function processTreeInventoryEvent() {
  236.     if ( InvEventExpected != 0 ) { // if  expected
  237.         InvEventExpected = null; // reset expected
  238.         //Delay 1/2 second then start processing of the expansion; allow time for all the expanded items to download
  239.         Tid = setTimeout("processIntroGraphMode()",500); // Delay 500 ms 
  240.     }
  241. }
  242.  
  243.